package com.sc.nft.hna.form;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.sc.nft.config.hna.HnaConfig;
import com.sc.nft.dto.HnaCardBindDTO;
import com.sc.nft.mapstruct.HnaMapStruct;
import lombok.Data;

import java.util.Map;

@Data
public class R007TransForm extends BaseTransForm {

  public static final String[] encryptArr =
      new String[] {
        "cardNo",
        "holderName",
        "cardAvailableDate",
        "cvv2",
        "mobileNo",
        "identityType",
        "identityCode",
        "userId",
        "merUserIp"
      };
  public static final String[] verifyArr =
      new String[] {
        "version",
        "tranCode",
        "merOrderId",
        "merId",
        "charset",
        "signType",
        "resultCode",
        "errorCode",
        "ncountOrderId"
      };
  public static final String[] submitArr =
      new String[] {
        "version",
        "tranCode",
        "merId",
        "merOrderId",
        "submitTime",
        "msgCiphertext",
        "signType",
        "signValue",
        "merAttach",
        "charset"
      };
  private static final long serialVersionUID = -6001027634291635502L;

  private String cardNo; // 支付银行卡卡号
  private String holderName; // 持卡人姓名
  private String cardAvailableDate; // 信用卡有效期
  private String cvv2; // 信用卡CVV2
  private String mobileNo; // 银行签约手机号
  private String identityType; // 证件类型
  private String identityCode; // 证件号码
  private String userId; // 用户ID
  private String merUserIp; // 商户用户IP

  public static final String MAIN_URL = "https://ncount.hnapay.com/api/r007.htm";
  public static final String TRAN_CODE = "R007";

  @Override
  public String getEncryptJsonStr() {
    return getJsonStr(this, encryptArr);
  }

  @Override
  public String getVerifyJsonStr() {
    return getJsonStr(this, verifyArr);
  }

  @Override
  public String getSubmitJsonStr() {
    return getJsonStr(this, submitArr);
  }

  public static Map<String, Object> generateParam(
      String userId, HnaConfig hnaConfig, HnaCardBindDTO dto) {
    R007TransForm transForm = HnaMapStruct.INSTANCE.dto2r007form(dto);
    transForm.setUserId(userId);
    transForm.initCommonParams(TRAN_CODE, hnaConfig.getMerId(), IdWorker.getIdStr(), "");
    return generateParam(transForm, hnaConfig);
  }
}
